<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>


    <script>
        // 使用Object创建通用对象
            var user=new Object();
            user.name="吕布";
            user.age=21;
            user.say=function(){
                console.log("大家好，我叫"+this.name+"，今年"+this.age);
            }
            user.say();


            var dog=new Object();
            dog.name="来福";
            dog.wang=function(){
                console.log(this.name+"饿了!");
            }
            dog.wang();



        // 使用构造函数
        function userinfo(name,age){
            this.name=name;
            this.age=age;
            this.say=function(){
                console.log("大家好，我叫"+this.name+"，今年"+this.age);
            }
        }
        var user1=new userinfo("邵重德",20);
        user1.say();

        
        //使用直接量
        var user2={
            username:"孙悟空",
            age:200,
            say:function(){
                console.log("大家好，我叫"+this.username+"，今年"+this.age);
            }
        };
        user2.say();
    </script>
</body>
</html>